package net.maku.generator.controller;

import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.maku.generator.common.utils.Result;
import net.maku.generator.config.StorageConfig;
import net.maku.generator.utils.EntityCommUtils;
import net.maku.generator.vo.ManualVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 代码模板树管理
 *
 * @author 代码小子 codeboy@126.com
 * @since 1.0.0 2024-11-09
 */
@Slf4j
@RestController
@RequestMapping("gen/manual")
@AllArgsConstructor
public class ManualController {

    @Resource
    private StorageConfig storageConfig;

    @GetMapping
    public Result<ManualVO> variables() {

        String variablesFilePath = storageConfig.generateRealFilePath("/upload/md/variables.md");
        String variablesContent = EntityCommUtils.readMdContent(variablesFilePath);

        String helperFilePath = storageConfig.generateRealFilePath("/upload/md/helper.md");
        String helperContent = EntityCommUtils.readMdContent(helperFilePath);

        ManualVO manual = new ManualVO();
        manual.setVariableDefinition(variablesContent);
        manual.setHelper(helperContent);

        return Result.ok(manual);
    }

}
